//
//  HCPhotoCell.m
//  ChatForHot
//
//  Created by wr on 2018/10/15.
//  Copyright © 2018年 FLY. All rights reserved.
//

#import "HCPhotoCell.h"
#import "HCPhotoManager.h"

@implementation HCPhotoCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self  = [super initWithFrame:frame]) {
        [self HOTCHATdidInitialized];
    }
    return self;
}

- (void)HOTCHATdidInitialized {
    self.backgroundColor = [UIColor colorFromHexString:@"EDEDED"];
    self.layer.cornerRadius = 2;
    self.clipsToBounds = YES;
    [self addSubview:self.HOTCHATimgView1];
    [self addSubview:self.HOTCHATimgView2];
    [self addSubview:self.HOTCHATtimeLab];
    [self addSubview:self.HOTCHATstateImgView];
    [self.HOTCHATimgView1 mas_updateConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    [self.HOTCHATstateImgView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    [self.HOTCHATtimeLab mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(10);
        make.height.mas_equalTo(25);
        make.bottom.equalTo(self);
    }];
    [self.HOTCHATimgView2 mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.equalTo(self);
        make.height.mas_equalTo(25);
    }];
}

- (void)setEntity:(HCAssetModel *)entity{
    _entity = entity;
    
    @weakify(self)
    [[HCPhotoManager shareManager] getPhotoWithAssetModel:entity photoWidth:100 completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
        @strongify(self)
        if (!isDegraded) {
            self.HOTCHATimgView1.image = photo;
        }
    }];
}

- (void)setIsSelected:(BOOL)isSelected{
    _isSelected = isSelected;
    self.HOTCHATstateImgView.hidden = !isSelected;
}

- (void)setIsVideo:(BOOL)isVideo{
    if (isVideo) {
        self.HOTCHATtimeLab.hidden = NO;
        self.HOTCHATimgView2.hidden = NO;
        self.HOTCHATtimeLab.text = self.entity.timeLength;
    }
}

- (UIImageView *)HOTCHATimgView1{
    if (_HOTCHATimgView1 == nil) {
        _HOTCHATimgView1 = [[UIImageView alloc] init];
        _HOTCHATimgView1.contentMode = UIViewContentModeScaleAspectFill;
        _HOTCHATimgView1.clipsToBounds = YES;
    }
    return _HOTCHATimgView1;
}

- (UIImageView *)HOTCHATstateImgView{
    if (_HOTCHATstateImgView == nil) {
        _HOTCHATstateImgView = [[UIImageView alloc] init];
        _HOTCHATstateImgView.image = [[UIImage imageNamed:@"photo_select"] resizableImageWithCapInsets:(UIEdgeInsetsMake(30, 10, 10, 30)) resizingMode:(UIImageResizingModeStretch)];
    }
    return _HOTCHATstateImgView;
}

- (UILabel *)HOTCHATtimeLab{
    if (_HOTCHATtimeLab == nil) {
        _HOTCHATtimeLab = [[UILabel alloc] init];
        _HOTCHATtimeLab.font = [UIFont systemFontOfSize:12];
        _HOTCHATtimeLab.textColor = [UIColor whiteColor];
        _HOTCHATtimeLab.hidden = YES;
    }
    return _HOTCHATtimeLab;
}
- (UIImageView *)HOTCHATimgView2{
    if (_HOTCHATimgView2 == nil) {
        _HOTCHATimgView2 = [[UIImageView alloc] init];
        _HOTCHATimgView2.image = [UIImage imageNamed:@"viodeo_time_bkg"];
        _HOTCHATimgView2.contentMode = UIViewContentModeScaleAspectFill;
        _HOTCHATimgView2.clipsToBounds = YES;
        _HOTCHATimgView2.hidden = YES;
    }
    return _HOTCHATimgView2;
}
@end
